<?php
//
///**
// * @category   Ahs
// * @package    Ahs_Auth
// * @subpackage Adapter
// * @author     Olivier Parent
// * @copyright  Copyright (c) 2011 Artevelde University College Ghent
// */
//class Ahs_Auth_Adapter_DbTableAMF extends Zend_Auth_Adapter_DbTable
//{
//
//    public function __construct()
//    {
//        $dbAdapter = Zend_Db_Table::getDefaultAdapter();
//        parent::__construct($dbAdapter);
//
//        $this->setTableName('users')
//             ->setIdentityColumn('user_email')
//             ->setCredentialColumn('user_password')
//             ->setCredentialTreatment('? AND user_active = TRUE AND user_deleted = FALSE')
//        ;
//    }
//
//    /**
//     * setCredential()
//     * 
//     * @param string $credential
//     * @return Ahs_Auth_Adapter_DbTable
//     */
//    public function setCredential($credential)
//    {
//        return parent::setCredential( sha1($credential) );
//    }
//    
//    /**
//     * setIdentity()
//     * 
//     * @param string $value
//     * @return Ahs_Auth_Adapter_DbTable
//     */
//    public function setIdentity($value)
//    {
//        return parent::setIdentity($value);
//    }
//    
//}



/**
 * @category   Ahs
 * @package    Ahs_Auth
 * @subpackage Adapter
 * @author     Olivier Parent
 * @copyright  Copyright (c) 2011 Artevelde University College Ghent
 */
class Ahs_Auth_Adapter_DbTableAMF extends Zend_Auth_Adapter_DbTable
{

    public function __construct()
    {
        $dbAdapter = Zend_Db_Table::getDefaultAdapter();
        parent::__construct($dbAdapter);

        $this->setTableName('users')
             ->setIdentityColumn('user_email')
             ->setCredentialColumn('user_password')
            // ->setCredentialTreatment('? AND user_active = TRUE AND user_deleted = FALSE')
             ->setCredentialTreatment('? AND user_active = TRUE')
        ;
    }

    /**
     * authenticate()
     * 
     * @return Zend_Auth_Result
     */
    public function authenticate()
    {
        $code = parent::authenticate()->getCode();
        $identity = $this->getResultRowObject();    
        $authResult = new Zend_Auth_Result($code, $identity);
       
        return $authResult;
    }    
    
    /**
     * setCredential()
     * 
     * @param string $credential
     * @return Ahs_Auth_Adapter_DbTable
     */
    public function setCredential($credential)
    {
       return parent::setCredential( sha1($credential) );
      // return parent::setCredential( Ahs_Utility::hash($credential) );
    }
    
    /**
     * setIdentity()
     * 
     * @param string $value
     * @return Ahs_Auth_Adapter_DbTable
     */
    public function setIdentity($value)
    {
        return parent::setIdentity($value);
    }
    
}

